package br.com.lucasddaniel.merchanmobile.adapter;

import java.text.SimpleDateFormat;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import br.com.lucasddaniel.merchanmobile.R;
import br.com.lucasddaniel.merchanmobile.bean.PasseioBean;

public class PasseiosRelatorioAdapter extends ArrayAdapter<PasseioBean> {
    private Context context = null;
    private List<PasseioBean> listPasseios = null;

    public PasseiosRelatorioAdapter(Context context, int resource, List<PasseioBean> listPasseios) {
        super(context, resource, listPasseios);
        this.context = context;
        this.listPasseios = listPasseios;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.row_passeio, parent, false);

        if (listPasseios != null && listPasseios.size() != 0) {
            PasseioBean passeioBean = (PasseioBean) listPasseios.get(position);
            if (passeioBean != null) {
                TextView nomeTurista = (TextView) rowView.findViewById(R.id_row_passeio.turistas_nome);
                TextView nomeGuia = (TextView) rowView.findViewById(R.id_row_passeio.guia_nome);
                TextView nomePousada = (TextView) rowView.findViewById(R.id_row_passeio.pousada_nome);
                TextView totalGeral = (TextView) rowView.findViewById(R.id_row_passeio.total_geral);
                TextView desconto = (TextView) rowView.findViewById(R.id_row_passeio.desconto);
                TextView dataHoraVendaPasseio = (TextView) rowView.findViewById(R.id_row_passeio.data);
                TextView sinal = (TextView) rowView.findViewById(R.id_row_passeio.sinal);
                TextView saldoFinal = (TextView) rowView.findViewById(R.id_row_passeio.saldo_final);
                TextView tipoDeMoeda = (TextView) rowView.findViewById(R.id_row_passeio.tipo_moeda);

                nomeTurista.setText(passeioBean.getNomeTurista());
                nomeGuia.setText(passeioBean.getNomeGuia());
                nomePousada.setText(passeioBean.getNomePousada());
                totalGeral.setText(passeioBean.getTotalGeral() + "");
                desconto.setText(passeioBean.getDesconto() + "");
                sinal.setText(passeioBean.getSinal() + "");
                saldoFinal.setText(passeioBean.getSaldoFinal() + "");
                tipoDeMoeda.setText("Real");
                if (passeioBean.getTipoDeMoeda().equalsIgnoreCase("0")) {
                    tipoDeMoeda.setText("Dólar");
                }
                SimpleDateFormat sdfData = new SimpleDateFormat("dd/MM/yyyy HH:mm");
                dataHoraVendaPasseio.setText(sdfData.format(passeioBean.getDataHoraVenda()));
                //                TableLayout myTable=new TableLayout(this);        
                //                TextView[][] myTextView=new TextView[3][3];
                //                myTable.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
                //                TableRow[] myRow=new TableRow[3];        
                //                for (int i = 0; i < 3; i++) {
                //                    myRow[i]=new TableRow(this);
                //                    myRow[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));           
                //                    for (int j = 0; j < 3; j++) {               
                //                        myTextView[i][j]=new TextView(this);  
                //                        myTextView[i][j].setText("Your Text");
                //                        myRow[i].addView(myTextView[i][j]);
                //                    }   
                //                    myTable.addView(myRow[i]);
                //                }
                //                LinearLayout lin=(LinearLayout)findViewById(R.id.linLayout);
                //                lin.addView(myTable);
                //                passeioBean.setImg(imgChecked);
                //                txtViewNome.setText(passeioBean.getNome());
                //                txtQuantidade.setText(passeioBean.getQuantidade() + "");
                //                txtViewMotorista.setText(passeioBean.getMotorista());
                //                txtViewOperador.setText(passeioBean.getOperador());
                //                if (passeioBean.isChecked()) {
                //                    passeioBean.getImg().setVisibility(View.VISIBLE);
                //                } else {
                //                    passeioBean.getImg().setVisibility(View.INVISIBLE);
                //                }
            }
        }
        return rowView;
    }

    @Override
    public int getCount() {
        return super.getCount();
    }
}
